package com.lesso.web;

import com.baomidou.mybatisplus.plugins.Page;
import com.lesso.util.ServiceResultUtil;
import top.ibase4j.core.base.result.QueryResultModel;
import top.ibase4j.core.base.result.ResultModel;
import top.ibase4j.core.base.result.ResultUtil;
import top.ibase4j.core.exception.ServiceException;
import top.ibase4j.model.Pagination;
import {{.table.PackageName}}.model.{{.table.ClassName}};
import {{.table.PackageName}}.model.vo.{{.table.ClassName}}VO;
import {{.table.PackageName}}.model.dto.{{.table.ClassName}}DTO;
import {{.table.PackageName}}.service.I{{.table.ClassName}}Service;
import com.lesso.validation.AddGroup;
import com.lesso.validation.QueryGroup;
import com.lesso.validation.UpdateGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.ibase4j.core.base.BaseController;

import java.util.List;
/**
 * {{.table.FunctionName}}Controller
 *
 * @author {{.table.FunctionAuthor}}
 * @since {{.table.CreateTime}}
*/
@RestController
@RequestMapping("/{{ .table.ClassName |CaseCamelLower}}")
@Api(value = "{{.table.FunctionName}}接口", tags = "{{.table.FunctionName}}接口")
public class {{.table.ClassName}}Controller extends BaseController<{{.table.ClassName}}, I{{.table.ClassName}}Service> {

       /**
       * POST {basePath}/{{ .table.ClassName |CaseCamelLower}}/getPageList 分页查询数据
       *
       * @param page 分页查询对象 {@link {{.table.ClassName}} 参数对象}
       * @return
       */
       @PostMapping("/getPageList")
       @ApiOperation(value = "分页查询数据")
       public QueryResultModel<List<{{.table.ClassName}}VO>> getPageListEntity(
       @RequestBody Pagination<{{.table.ClassName}}DTO> page) throws ServiceException {
           Page<{{.table.ClassName}}VO> resultPage = this.getService().getPageList(page);
           return ServiceResultUtil.success(resultPage.getTotal(), resultPage.getRecords(), "查询成功");
       }


        /**
        * POST {basePath}/{{ .table.ClassName |CaseCamelLower}}/getList 查询{{.table.FunctionName}}列表
        *
        * @param param 参数对象 {@link {{.table.ClassName}} 参数对象}
        * @return result
        */
        @PostMapping("/getList")
        @ApiOperation(value = "查询{{.table.FunctionName}}列表")
        public QueryResultModel<List<{{.table.ClassName}}VO>> getList(@RequestBody @Validated(QueryGroup.class) {{.table.ClassName}} param) throws ServiceException {
            List<{{.table.ClassName}}VO> list = this.getService().getList(param);
            Long total = (long) list.size();
            return ResultUtil.success(total, list, "查询成功");
        }


        /**
         * GET {basePath}/{{ .table.ClassName |CaseCamelLower}}/{id} {{.table.FunctionName}}详情
         *
         * @param id {{.table.FunctionName}}id
         * @return
        */
        @GetMapping("/{id}")
        @ApiOperation(value = "{{.table.FunctionName}}详情")
        public QueryResultModel<{{.table.ClassName}}VO> get(@PathVariable("id") {{.table.PkColumn.JavaType}} id) throws ServiceException {
            return this.getService().getById(id);
        }

        /**
         * POST {basePath}/{{ .table.ClassName |CaseCamelLower}}/add 新增{{.table.FunctionName}}记录
         *
         * @param entity 参数对象 {@link {{.table.ClassName}} 参数对象}
         * @return result
        */
        @PostMapping("/add")
        @ApiOperation(value = "新增{{.table.FunctionName}}记录")
        public ResultModel add(@RequestBody @Validated(AddGroup.class) {{.table.ClassName}} entity) throws ServiceException {
            return this.getService().add(entity);
        }

        /**
         * POST {basePath}/{{ .table.ClassName |CaseCamelLower}}/modify 更新{{.table.FunctionName}}记录
         *
         * @param entity 参数对象 {@link {{.table.ClassName}} 参数对象}
         * @return result
        */
        @PostMapping("/modify")
        @ApiOperation(value = "更新{{.table.FunctionName}}记录")
        public ResultModel modify(@RequestBody @Validated(UpdateGroup.class) {{.table.ClassName}} entity) throws ServiceException {
            return this.getService().modify(entity);
        }

        /**
         * POST {basePath}/{{ .table.ClassName |CaseCamelLower}}/batchDisabled 批量禁用{{.table.FunctionName}}记录
         *
         * @param ids 参数对象 ids
         * @return result
        */
        @PostMapping("/batchDisabled")
        @ApiOperation(value = "批量禁用{{.table.FunctionName}}")
        public ResultModel batchDisabled(@RequestBody List<{{.table.PkColumn.JavaType}}> ids) {
            return this.getService().batchDisabled(ids);
        }

        /**
         * POST {basePath}/{{ .table.ClassName |CaseCamelLower}}/batchEnabled 批量启用{{.table.FunctionName}}记录
         *
         * @param ids 参数对象 ids
         * @return result
        */
        @PostMapping("/batchEnabled")
        @ApiOperation(value = "批量启用{{.table.FunctionName}}")
        public ResultModel batchEnabled(@RequestBody List<{{.table.PkColumn.JavaType}}> ids) {
            return this.getService().batchEnabled(ids);
        }


}